package com.sz.ruichar.manager.inteceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.sz.ruichar.utils.system.HttpUtils;

@Component
public class AccessInterceptor extends HandlerInterceptorAdapter
{
	private static final Logger LOGGER = LoggerFactory.getLogger(AccessInterceptor.class);
	@Value("${accessIpList}")  
	private String accessIpList;
	private final String ACCIPFLAG = "close";
    @Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object obj, ModelAndView modelView) throws Exception 
	{
		super.postHandle(request, response, obj, modelView);
	}
    
    @Override
   	public boolean preHandle(HttpServletRequest request,HttpServletResponse response, Object handler) throws Exception 
    {
    	boolean preHandleStatus = true;
//    	if(StringUtils.isEmpty(accessIpList) || accessIpList.contains(ACCIPFLAG))
//    	{
//    		LOGGER.error("======close te accessIpList limit ====");
//    		return preHandleStatus;
//    	}
//    	if(null == accessIpList || accessIpList.isEmpty())
//    	{
//    		LOGGER.error("======no access ip can be accessed");
//    		preHandleStatus = false;
//    		response.setStatus(HttpServletResponse.SC_FORBIDDEN);
//    	}
//    	else
//    	{
//    		String remoteIp = HttpUtils.getIpAddress(request);
//    		if(!accessIpList.contains(remoteIp))
//    		{
//    			preHandleStatus = false;
//    			LOGGER.info("=============remote ip {} is not permitted to access the server",remoteIp);
//    			response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
//    		}
//    	}
    	return preHandleStatus;
    }


}
